package com.bra.ui.fragment;

import java.io.File;
import java.util.HashMap;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import com.bra.R;
import com.bra.ui.activity.LoginActivity;
import com.bra.ui.activity.RegistActivity;
import com.bra.ui.activity.SetActivity;
import com.bra.ui.base.BaseActivity;
import com.bra.ui.base.BaseFragment;
import com.bra.utils.CameraUtilsLister;
import com.bra.utils.DialogUtil;
import com.bra.utils.SPHelper;
import com.bra.view.RoundImageView;
//我的界面fragment
public class MineFragment extends BaseFragment {
	private RoundImageView mine_head;
	private Button mine_regist, mine_login;
	private CameraUtilsLister camera;
	private ImageView mine_shezhi;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return getRootView(R.layout.fragment_mine);
	}

	@Override
	protected void fillData() {

	}

	@Override
	protected void findView() {
		mine_head = (RoundImageView) rootView.findViewById(R.id.mine_head);
		mine_head.setOnClickListener(click);
		mine_regist = (Button) rootView.findViewById(R.id.mine_regist);
		mine_regist.setOnClickListener(click);
		mine_login = (Button) rootView.findViewById(R.id.mine_login);
		mine_login.setOnClickListener(click);
		mine_shezhi=(ImageView) rootView.findViewById(R.id.mine_shezhi);
		mine_shezhi.setOnClickListener(click);
	}

	public View.OnClickListener click = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.mine_head:
				camera = new CameraUtilsLister(getActivity());
				OnClickListener camera_lister = camera.camera_lister;
				String[] args = { "拍照", "相册" };
				DialogUtil.showSelectDialog(getActivity(), "请选择", args, 0,
						camera_lister);
				break;
			case R.id.mine_regist:
				Bundle bundle = new Bundle();				
				((BaseActivity) getActivity()).goActivity(RegistActivity.class, bundle);					
				break;
			case R.id.mine_login:
				((BaseActivity) getActivity()).goActivity(LoginActivity.class);
				break;
			case R.id.mine_shezhi:
				((BaseActivity) getActivity()).goActivity(SetActivity.class);
				break;
			default:
				break;
			}

		}
	};
	public static String SDCARD = Environment.getExternalStorageDirectory()
			+ "/Android/data/evmanager/iamge/";
	private File userfaceFile;
	@SuppressWarnings("unused")
	private Bitmap defaultIcon;
	private boolean is_up = false;

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

		String name_hu = SPHelper.readString(getActivity(), "phone_name");
		if (!"".equals(name_hu)) {
			userfaceFile = new File(SDCARD + name_hu + ".jpg");
			if (userfaceFile != null) {
				Bitmap bm = BitmapFactory.decodeFile(SDCARD + name_hu + ".jpg");
				if (bm != null) {
					mine_head.setImageBitmap(bm);
				}
			}
		}
	}
}
